package com.xinyue.auto.reader.major;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import com.xinyue.auto.annotation.ListClear;
import com.xinyue.auto.bean.Query;
import com.xinyue.auto.reader.Process;
import com.xinyue.auto.reader.ProcessContext;
import com.xinyue.auto.util.StringUtil;

public abstract class FindMajor extends ProcessContext{
	public FindMajor(Process read) {
		super(read);
	}
	
	//查询方法集合
	@ListClear
	protected List<Query> querys = new ArrayList<Query>();
	
	/**
	 * 读取fand标签下的query、hql、sql标签的共有属性
	 * @param find
	 * @return
	 * @throws Exception
	 */
	protected Query commonRead(Element find) throws Exception {
		String method = find.attributeValue(method_);
		//方法名称
		if(StringUtil.isNull(method)) {
			throw new Exception("未定义method属性或其值为空");
		}
		
		Query query = new Query();
		
		query.setMethod(method);
		//是否是查询类型
		if("false".equals(find.attributeValue(query_))) {
			query.setQuery(false);
		}else {
			query.setQuery(true);
		}
		
		return query;
	}
	
	@Override
	protected void install() {
		holder.getEntity().getFinds().addAll(querys);
	}
}